package com.jeasonzhao.report.model;

import com.jeasonzhao.commons.basic.StringPairCollection;
import com.jeasonzhao.model.Model;
import com.jeasonzhao.model.ModelField;
import com.jeasonzhao.report.codes.DatabaseTypes;

@Model("database")
public class ReportDatabaseConfiguration extends BaseReportModelItem
{
    private static final long serialVersionUID = 1L;
    @ModelField(names = "type,databasetype")
    private DatabaseTypes databaseType = DatabaseTypes.NormalDatabase;

    private String databaseId = null;
    private String databaseName = null;
    private String driver = null;
    private String url = null;
    private String userName = null;
    private String password = null;
    private int poolCapcity = -1;
    private int poolActive = -1;
    private String className = null;
    private StringPairCollection appendParams = null;

    public ReportDatabaseConfiguration()
    {
    }

    public String toString()
    {
        return this.getDatabaseId() + ":" + this.getDatabaseName() +
            "{" + this.getConfigType().getName() + ":" + this.getConfigSrc() + "}";
    }

    public boolean isUsingDatabasePool()
    {
        return this.poolCapcity > 0;
    }

    public String getDatabaseId()
    {
        return databaseId;
    }

    public String getDatabaseName()
    {
        return databaseName;
    }

    public String getDriver()
    {
        return driver;
    }

    public String getUrl()
    {
        return url;
    }

    public String getPassword()
    {
        return password;
    }

    public int getPoolActive()
    {
        return poolActive;
    }

    public int getPoolCapcity()
    {
        return poolCapcity;
    }

    public String getUserName()
    {
        return userName;
    }

    public DatabaseTypes getDatabaseType()
    {
        return databaseType;
    }

    public StringPairCollection getAppendParams()
    {
        return appendParams;
    }

    public void setPoolCapcity(int poolCapcity)
    {
        this.poolCapcity = poolCapcity;
    }

    public void setUserName(String userName)
    {
        this.userName = userName;
    }

    public void setPoolActive(int poolActive)
    {
        this.poolActive = poolActive;
    }

    public void setPassword(String password)
    {
        this.password = password;
    }

    public void setUrl(String jdbcUrl)
    {
        this.url = jdbcUrl;
    }

    public void setDatabaseName(String databaseName)
    {
        this.databaseName = databaseName;
    }

    public void setDatabaseId(String databaseId)
    {
        this.databaseId = databaseId;
    }

    public void setDriver(String jdbcDriver)
    {
        this.driver = jdbcDriver;
    }

    public void setDatabaseType(DatabaseTypes databaseType)
    {
        this.databaseType = databaseType;
    }

    public void setAppendParams(StringPairCollection appendParams)
    {
        this.appendParams = appendParams;
    }

    public String getParameter(String ...params)
    {
        if(null == params || null == this.appendParams)
        {
            return null;
        }
        for(String strP : params)
        {
            if(null == strP)
            {
                continue;
            }
//            appendParams.findByIdLoose()
        }
        /**
         * @todo Code here
         */
        return null;
    }

    public String getClassName()
    {
        return this.className;
    }

    public void setClassName(String v)
    {
        this.className = v;
    }
}
